<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>数据统计 -- 门店销售汇总</title>
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap.min.css">
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css">
    <link href="${contextPath}/static/ztree/css/zTreeStyle.css" rel="stylesheet"/>
    <script src="${contextPath}/static/statistics/js/jquery.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="${contextPath}/static/statistics/js/vue.js"></script>
    <script src="${contextPath}/static/statistics/js/echarts.min.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="${contextPath}/static/util/my-autocomplete.js"></script>
    <script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>
    <style>
        .spinner {
            margin: 11px auto 0;
            height: 20px;
            text-align: center;
        }

        .spinner > div {
            width: 10px;
            height: 10px;
            background-color: #67CF22;

            border-radius: 100%;
            display: inline-block;
            -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
            animation: bouncedelay 1.4s infinite ease-in-out;
            /* Prevent first frame from flickering when animation starts */
            -webkit-animation-fill-mode: both;
            animation-fill-mode: both;
        }

        .spinner .bounce1 {
            -webkit-animation-delay: -0.32s;
            animation-delay: -0.32s;
        }

        .spinner .bounce2 {
            -webkit-animation-delay: -0.16s;
            animation-delay: -0.16s;
        }

        @-webkit-keyframes bouncedelay {
            0%, 80%, 100% {
                -webkit-transform: scale(0.0)
            }
            40% {
                -webkit-transform: scale(1.0)
            }
        }

        @keyframes bouncedelay {
            0%, 80%, 100% {
                transform: scale(0.0);
                -webkit-transform: scale(0.0);
            }
            40% {
                transform: scale(1.0);
                -webkit-transform: scale(1.0);
            }
        }

        .autocomplete-suggestions {
            border: 1px solid #999;
            background: #FFF;
            overflow: auto;
        }

        .autocomplete-suggestion {
            padding: 2px 5px;
            white-space: nowrap;
            overflow: hidden;
        }

        .autocomplete-selected {
            background: #F0F0F0;
        }

        .autocomplete-suggestions strong {
            font-weight: normal;
            color: #3399FF;
        }

        @-moz-document url-prefix() {
            fieldset {
                display: table-cell;
            }
        }

        th td{text-align: center}
    </style>
</head>
<body style="background: rgba(119, 118, 118, 0.15);">
<div class="container-fluid" id="app">
    <div class="row">
        <h4 class="col-sm-6 col-xs-9">门店销售汇总实时数据：</h4>
        <div class="spinner  col-sm-6 col-xs-3" style="text-align: right;" title="正在实时获取数据标志">
            <div class="bounce1"></div>
            <div class="bounce2"></div>
            <div class="bounce3"></div>
        </div>
    </div>

    <form class="form-inline">
        <!--
        <%--<shiro:hasPermission name="CLOUDERPORDERSPLADMINORDER:STATISTICS">--%>
            <div class="form-group">
                <input id="quXianNameInput" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="区县">
            </div>
        <%--</shiro:hasPermission>--%>

        <%--<shiro:lacksPermission name="CLOUDERPORDERSPLEMPORDER:STATISTICS">--%>
            <%--<shiro:lacksPermission name="CLOUDERPORDERSPLCHANNELORDER:STATISTICS">--%>

                <div class="form-group">
                    <input id="channelNameId" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="渠道">
                </div>
            <%--</shiro:lacksPermission>--%>
            <div class="form-group">
                <input id="empNameInput" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="客户经理">
            </div>
        <%--</shiro:lacksPermission>--%>
        -->
        <div class="form-group">
            <input id="shopNameId" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="店铺" style="width: 280px;">
        </div>
        <!--
        <div class="form-group">
            <input id="orderLevelInput" onfocus="this.value=''" class="form-control input-sm" type="text" placeholder="档位名称">
        </div>
        <div class="form-group">
            <select class="form-control input-sm" id="isExp">
                <option value="-1">--是否试点--</option>
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
        <div class="form-group">
            <input id="cityTypeInput" class="form-control input-sm" type="text" placeholder="经营类型">
        </div>
        -->
        <div class="form-group">
            <input id="beginTimeInput" class="form-control input-sm" type="text" placeholder="选择开始销售时间">
        </div>
        <div class="form-group">
            <input id="endTimeInput" class="form-control input-sm" type="text" placeholder="选择结束销售时间">
        </div>
        <!--
        <div class="form-group input-group hide">
            <input id="prodNameInput" class="form-control input-sm" readonly type="text" placeholder="未选择商品">
            <span class="input-group-btn">
				<button type="button" class="btn btn-default btn-sm" title="选择商品作为查询条件" data-toggle="modal"
                        data-target="#gridSystemModal">选择</button>
        	</span>
        </div>
        -->
        <div class="form-group">
            <select class="form-control input-sm" id="prodType">
                <option value="">商品类型</option>
                <option value="05">卷烟</option>
                <option value="03">休闲食品</option>
                <option value="04">粮油</option>
                <option value="06">日配（冷冻、冷藏）</option>
                <option value="07">冲饮</option>
                <option value="08">鲜食及自制饮品</option>
                <option value="09">进口商品</option>
                <option value="10">个人清洁</option>
                <option value="11">家用清洁</option>
                <option value="12">家庭消耗品</option>
                <option value="13">百货、纺织类及小家电</option>
                <option value="14">兑换品耗材及服务项目</option>
                <option value="15">特殊商品</option>
                <option value="16">烟具及烟嘴</option>
                <option value="01">酒</option>
                <option value="02">饮料及常温液态奶制品</option>
            </select>
        </div>
        <button type="button" class="btn btn-success btn-sm" title="默认查询近一个月的数据" onclick="selectScratchoff();">查询
        </button>
        <button type="button" class="btn  btn-info btn-sm" onclick="exportExcel();" title="按照查询条件导出到Excel">导出Excel</button>
        <button type="button" class="btn btn-warning btn-sm" onclick="autogetData();" title="实时拉取最新的订单数据">实时获取</button>
        <button type="button" class="btn btn-warning btn-sm" onclick="javascript:window.history.go(-2);window.close();" title="返回">返回</button>
    </form>


    <div class="table-responsive" id="tableContainer" style="margin-top: 10px;overflow-y: auto">
        <table class="table table-striped table-condensed" style="width:1600px;">
            <thead style="background-color: rgb(53, 181, 202);">
            <tr style="color: rgb(248, 248, 248);">
                <th>序号</th>
                <th>订单编号</th>
               <%-- <th>渠道</th>
                <th>客户</th>--%>
                <th>店铺</th>
                <th>商品编号</th>
                <th>商品</th>
                <th>销量</th>
                <th>销售单价</th>
                <th>单品金额</th>
                <th>优惠额</th>
                <th>订单总价</th>
                <th>订单优惠额</th>
                <%--<th>实际支付</th>--%>
                <%--<th>累计销量</th>--%>
                <th>售货员</th>
                <th>消费ID</th>
                <%--<th>电话号码</th>--%>
                <th>销售时间</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(order,index) in orderList">
                <td>{{index+1}}</td>
                <td>{{order.id}}</td>
                <%--<td>{{order.channelName}}</td>
                <td>{{order.custName}}</td>--%>
                <td>{{order.shopName}}</td>
                <td>{{order.barCode}}</td>
                <td><span v-if="order.prodName=='' || order.prodName==null">未知商品</span><span
                        v-if="order.prodName!='' && order.prodName!=null">{{order.prodName}}</span></td>
                <td>{{order.quantity}}</td>
                <td>{{order.price}}</td>
                <td>{{order.quantityPrice}}</td>
                <td>{{order.benefitPrice}}</td>
                <%--<td>{{order.totalPrice}}</td>--%>
                <td>{{order.amt}}</td>
                <td>{{order.benefitAmt}}</td>
                <%--<td>{{order.sales}}</td>--%>
                <td>{{order.username}}</td>
                <td><a href="javascript:void(0)" style="color: #0aa5df;" @click="showCustomerInfo(order.customerId,order.shopId,order.type)">{{order.customerId}}</a></td>
                <%--<td>{{order.mobile}}</td>--%>
                <td>{{order.operatorTime}}</td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12 col-md-4 col-lg-4 main" id="main1" style="margin-top: 10px;"></div>
        <div class="col-sm-12 col-xs-12 col-md-4 col-lg-4 main" id="main3" style="margin-top: 10px;"></div>
        <div class="col-sm-12 col-xs-12 col-md-4 col-lg-4 main" id="main2" style="margin-top: 10px;"></div>
    </div>
    <!-- 消费者相关信息modal -->
    <div id="customerDetailContent" class="hide">
        <div class="widget-body">
                <div class="widget-main padding-24">
                    <div class="row">
                        <div class="col-sm-6">
                            <ul class="list-unstyled spaced">
                                <li>
                                    <i class="ace-icon fa fa-caret-right blue"></i><strong>消费者姓名：</strong>{{customerInfo.NAME}}
                                </li>

                                <li>
                                    <i class="ace-icon fa fa-caret-right blue"></i><strong>消费者电话：</strong>{{customerInfo.MOBILE}}
                                </li>
								
								<li>
									<i class="ace-icon fa fa-caret-right blue"></i><strong>消费者脸部ID：</strong>{{customerInfo.FACEID}}
								</li>
								
                                <li>
                                    <i class="ace-icon fa fa-caret-right blue"></i><strong>消费者性别：</strong>{{customerInfo.SEX == '-1' ?  '未知' : customerInfo.SEX == '0' ? '男' : '女' }}
                                </li>
                                <li>
                                    <i class="ace-icon fa fa-caret-right blue"></i><strong>消费者年龄：</strong>{{customerInfo.AGE}}
                                </li>
                            </ul>
                        </div>

                        <div class="col-sm-6">
                            <ul class="list-unstyled spaced">

                            </ul>
                        </div>
                    </div><!-- /.col -->
                </div>
            </div>
    </div>
</div>

<form action="${contextPath}/ktcount/exportExcel" method="post" id="exportExcel" style="display:none">
    <input type="hidden" id="exportExcelData-quXianName" name="stringMap['quXianName']">
    <input type="hidden" id="exportExcelData-channelName" name="stringMap['channelName']">
    <input type="hidden" id="exportExcelData-shopName" name="stringMap['shopName']">
    <input type="hidden" id="exportExcelData-empName" name="stringMap['empName']">
    <input type="hidden" id="exportExcelData-isExp" name="stringMap['isExp']">
    <input type="hidden" id="exportExcelData-cityType" name="stringMap['cityType']">
    <input type="hidden" id="exportExcelData-orderLevel" name="stringMap['orderLevel']">
    <input type="hidden" id="exportExcelData-productCode" name="stringMap['productCode']">
    <input type="hidden" id="exportExcelData-beginTime" name="stringMap['beginTime']">
    <input type="hidden" id="exportExcelData-endTime" name="stringMap['endTime']">
    <input type="hidden" name="tableType" value="shipmentOrder">
</form>

<div class="modal fade" tabindex="-1" role="dialog" id="gridSystemModal" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="gridSystemModalLabel">选择商品</h4>
            </div>
            <div class="modal-body">
                <div class="content_wrap">
                    <div class="zTreeDemoBackground left">
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="selectProductTreeNames();">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script src=${contextPath}/static/layer/layer.js></script>
<script type="text/javascript">

    $("").addClass()

    var turnTime = format(new Date(),"yyyy_MM_dd");
    var time = format(new Date(),"yyyy-MM-dd");

    var queryModel = {}

    var app = new Vue({
        el: '#app',
        data: {
            orderList: [],
            productCode: "",
            customerInfo : {},
        },
        methods : {
            showCustomerInfo : function (customerId,shopId,type) {
                if (!customerId || !customerId) {
                    return
                }
                var vm = this
                layer.load(1)
                $.ajax({
                    url:  '${contextPath}/page/getCustomerInfoByIdAndType',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        customerId: customerId,
                        shopId : shopId,
                        type : type,
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        if (!data.success) {
                            layer.msg(data.message);
                            return
                        }
                        if (window.console) console.log(data)
                        vm.customerInfo = data.data;
                        $("#customerDetailContent").removeClass("hide")
                        layer.open({
                            type: 1,
                            title: '消费者信息详情',
                            closeBtn: 1,
                            shadeClose: true,
                            maxmin: true,
                            area: ['600px', '300px'],
                            skin: 'yourclass',
                            content: $("#customerDetailContent"),
                            end: function () {
                                $("#customerDetailContent").addClass("hide")
                            }
                        });

                    }
                    ,
                    error: function (error) {
                        layer.closeAll('loading')
                        layer.msg('网络错误')
                    }
                });
            }
        }
    })


    $(".main").height($(window).height() * 0.55)
    //$("#main1").width($(window).width()*0.3333);
    var myChart1 = echarts.init($("#main1")[0])
    var myChart2 = echarts.init($("#main2")[0])
    var myChart3 = echarts.init($("#main3")[0])

    var option = {
        color: ['#4690FF', '#A3D2F7'],
        title: {
            //text: '最近七天订单统计'
        },
        tooltip: {
            trigger: 'axis'
        },
        toolbox: {
            feature: {
                dataView: {
                    show: false,
                    readOnly: false
                },
                restore: {
                    show: false
                },
                saveAsImage: {
                    show: false
                }
            }
        },
        grid: {
            containLabel: true
        },
        legend: {
            data: ['金额', '订单']
        },
        xAxis: [{
            type: 'category',
            axisTick: {
                alignWithLabel: true
            },
            axisLabel: {
                interval: 0,
                rotate: 45,
                show: true,
                splitNumber: 15,
                textStyle: {
                    fontFamily: "微软雅黑",
                    fontSize: 12
                }
            },
            data: []
        }],
        yAxis: [{
            type: 'value',
            name: '金额',
            position: 'right',
            axisLabel: {
                formatter: '{value} 万元'
            }
        }, {
            type: 'value',
            name: '订单',
            position: 'left',
            axisLabel: {
                formatter: '{value} 笔'
            }
        }],
        series: [{
            name: '金额',
            type: 'line',
            label: {
                normal: {
                    show: true,
                    position: 'top',
                }
            },
            data: []
        }, {
            name: '订单',
            type: 'line',
            yAxisIndex: 1,
            label: {
                normal: {
                    show: true,
                    position: 'top',
                }
            },
            data: []
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart1.setOption(option)
    myChart2.setOption(option)
    myChart3.setOption(option)

    var changeData = function (orderArray) {
        //var appData = app.orderList;
        //console.log(appData)
        //appData.pop();
        app.orderList.unshift(orderArray)

        /*		{
         orderNo : 'FDS34324-0',
         modifiTimeStr : '2016-12-11 18:18:18',
         jigouCode : '9807899700',
         jigouName : '健康的',
         kehujinli: '你色即是空',
         custCode : '23132133',
         orderType : '43',
         payStatus : '支付失败',
         number : '43',
         price : '8930.23'
         }*/
        //app.orderList = appData
    }

    var countNum = 1;
    var intervalGetOrder = function () {
        var order = app.orderList[0]
        var lastCreateTime = ""
        if (order) {
            lastCreateTime = order.operatorTime;
        }
        //var lastCreateTime = "2017-01-11 18:18:18"
        console.log(lastCreateTime)
        //console.log('第' + (countNum++) + '次获取数据')
        $.ajax({
            url: '${contextPath}/ktcount/getShipmentOrder?lastOrderTime=' + lastCreateTime, //localhost:8080

            success: function (data) {
                if (data.success) {
                    var dataArray = data.data.ShipmentOrderList

                    if (dataArray.length > 0) {
                        var appOrderList = dataArray.concat(app.orderList)


                        if (appOrderList.length > 50) {
                            appOrderList = appOrderList.slice(0, 51)
                        }


/*                        var lastData = appOrderList[appOrderList.length - 1];
                        if (lastData.shopName == "合计：") {
                            appOrderList.pop();
                        }
                        var numTotal = {};
                        numTotal.shopName = "合计："
                        var totalPrice = 0;
                        var benefitPrice = 0;
                        var amt = 0;
                        var quantity = 0;
                        //var sales = 0;
                        //var stock = 0;

                        for (var index in  appOrderList) {
                            //console.log(appOrderList)
                            totalPrice = numAdd(appOrderList[index].totalPrice, totalPrice);
                            benefitPrice = numAdd(appOrderList[index].benefitPrice, benefitPrice);
                            amt = numAdd(appOrderList[index].amt, amt);
                            quantity = numAdd(appOrderList[index].quantity, quantity);
                            //sales = numAdd(appOrderList[index].sales, sales);
                            //stock = numAdd(appOrderList[index].stock, stock);
                        }
                        numTotal.totalPrice = totalPrice
                        numTotal.benefitPrice = benefitPrice
                        numTotal.amt = amt
                        numTotal.quantity = quantity
                        //numTotal.sales = sales
                        //numTotal.stock = stock
                        numTotal.prodName = " "
                        appOrderList.push(numTotal)*/

                        app.orderList = appOrderList
                    }

                    //console.log(data.data.SPLOrderDayData)
//                    var SPLOrderDayDataObj = data.data.ShipmentOrderDayData;
//                    var SPLOrderMonthDataObj = data.data.ShipmentOrderMonthData;
//                    var SPLOrderYearDataObj = data.data.ShipmentOrderYearData;
//                    if (SPLOrderDayDataObj != null) {
//                        updateOrderDayData(SPLOrderDayDataObj)
//                        updateOrderMonthData(SPLOrderMonthDataObj)
//                        updateOrderYearData(SPLOrderYearDataObj)
//                    }
                    getShipmentOrderOX();
                } else if (data.success == undefined) {
                    window.location.href = "${contextPath}"
                }
                //console.log(data.data)
                //console.log('数据长度为：' + dataArray.length)
            },
            error: function (error) {
                //console.log(error)
            }
        })
    }
    var intervalId;
    intervalId = setInterval(intervalGetOrder, "20000");

    $("#tableContainer").css("border", "1px solid gray");
    //改变div的高度
    $("#tableContainer").height($(window).height() * 0.35);

    function updateOrderDayData(data) {
        myChart1.setOption({
            title: {
                text: '天趋势统计'
            },
            xAxis: {
                data: data.dayNums
            },
            series: [{
                // 根据名字对应到相应的系列
                name: '金额',
                type: 'line',
                lineStyle: {
                    normal: {
                        width: 3,
                        shadowColor: 'rgba(0,0,0,0.4)',
                        shadowBlur: 10,
                        shadowOffsetY: 10
                    }
                },
                data: data.priceSums
            }, {
                name: '订单',
                type: 'line',
                lineStyle: {
                    normal: {
                        width: 3,
                        shadowColor: 'rgba(0,0,0,0.4)',
                        shadowBlur: 10,
                        shadowOffsetY: 10
                    }
                },
                data: data.countNums
            }]
        });

    }

    function updateOrderMonthData(data) {
        myChart2.setOption({
            title: {
                text: '月趋势统计'
            },
            xAxis: {
                data: data.dayNums
            },
            series: [{
                // 根据名字对应到相应的系列
                name: '金额',
                type: 'bar',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                    }
                },
                data: data.priceSums
            }, {
                // 根据名字对应到相应的系列
                name: '订单',
                type: 'bar',
                yAxisIndex: 1,
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                    }
                },
                data: data.countNums
            }]
        });

    }

    function updateOrderYearData(data) {
        myChart3.setOption({
            title: {
                text: '周趋势统计'
            },
            xAxis: {
                data: data.dayNums
            },
            series: [{
                // 根据名字对应到相应的系列
                name: '金额',
                type: 'line',
                lineStyle: {
                    normal: {
                        width: 3,
                        shadowColor: 'rgba(0,0,0,0.4)',
                        shadowBlur: 10,
                        shadowOffsetY: 10
                    }
                },
                data: data.priceSums
            }, {
                // 根据名字对应到相应的系列
                name: '订单',
                type: 'bar',
                yAxisIndex: 1,
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                    }
                },
                data: data.countNums
            }]
        });

    }

    intervalGetOrder()
    //var nowDate = new Date();
    // nowDate.setMonth(nowDate.getMonth()-1);
    $('#beginTimeInput').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        // startDate:nowDate,
    }).on('changeDate', function (e) {
        var startTime = e.date;
        $('#endTimeInput').datetimepicker('setStartDate', startTime);
    });
    $('#endTimeInput').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    }).on('changeDate', function (e) {
        var endTime = e.date;
        $('#beginTimeInput').datetimepicker('setEndDate', endTime);
    });

    var selectScratchoff = function () {
        var quXianName = $("#quXianNameInput").val();
        var channelName = $("#channelNameId").val();
        var shopName = $("#shopNameId").val();
        var empName = $("#empNameInput").val();
        var beginTime = $("#beginTimeInput").val();
        var endTime = $("#endTimeInput").val();
        var isExp = $("#isExp").val();
        var prodType = $("#prodType").val();
        var cityType = $("#cityTypeInput").val();
        var orderLevel = $("#orderLevelInput").val();
        if (quXianName == "" && beginTime == "" && endTime == "" && shopName == "" && channelName == "" && app.productCode == "" && orderLevel == "" && cityType == "" && prodType == "") {
            layer.msg("请至少选择除试点店以外的一个查询条件")
            return
        }
        layer.load(1);
        clearInterval(intervalId);
        $(".spinner").addClass("hide");
        $.ajax({
            url: '${contextPath}/ktcount/getKtShipmentOrderByTime',
            type: 'post',
            dataType: 'json',
            data: {
                stringMap: {
                    quXianName: quXianName,
                    beginTime: beginTime,
                    endTime: endTime,
                    shopName: shopName,
                    empName: empName,
                    channelName: channelName,
                    productCode: app.productCode,
                    isExp: isExp,
                    prodType: prodType,
                    orderLevel: orderLevel,
                    cityType: cityType,
                    shopType: '1',
                },

            },
            success: function (data) {
                if (data.success) {
                    var array = data.data;
                    if (array.length > 0) {

//                        setInterval(intervalGetOrder, "20000");
             /*           var numTotal = {};
                        numTotal.shopName = "合计：" + (array.length) + "条记录"
                        var totalPrice = 0;
                        var benefitPrice = 0;
                        var amt = 0;
                        var quantity = 0;
                        //var sales = 0;
                        //var stock = 0;

                        for (var index in  array) {
                            //console.log(appOrderList)
                            totalPrice = numAdd(array[index].totalPrice, totalPrice);
                            benefitPrice = numAdd(array[index].benefitPrice, benefitPrice);
                            amt = numAdd(array[index].amt, amt);
                            quantity = numAdd(array[index].quantity, quantity);
                           // sales = numAdd(array[index].sales, sales);
                           // stock = numAdd(array[index].stock, stock);
                        }
                        numTotal.totalPrice = totalPrice
                        numTotal.benefitPrice = benefitPrice
                        numTotal.amt = amt
                        numTotal.quantity = quantity
                        //numTotal.sales = sales
                       // numTotal.stock = stock
                        numTotal.prodName = " "
                        array.unshift(numTotal)*/

                        app.orderList = array;
                        getShipmentOrderOX();
                    } else {
                        layer.msg("所选条件没有数据")
                    }
                } else {
                    layer.msg(data.message);
                }
                layer.closeAll('loading')
            },
            error: function (error) {
                layer.msg("网络连接失败")
                layer.closeAll('loading')
            }
        })
    }

    var autogetData = function () {
        if ($(".spinner").hasClass("hide") == false) {
            layer.msg("已经在实时获取数据")
            return
        }
        intervalId = setInterval(intervalGetOrder, "10000");
        $(".spinner").removeClass("hide")
    }

        var exportExcel = function () {

            var quXianName = $("#quXianNameInput").val();
            var channelName = $("#channelNameId").val();
            var shopName = $("#shopNameId").val();
            var empName = $("#empNameInput").val();
            var isExp = $("#isExp").val();
            var cityType = $("#cityTypeInput").val();
            var orderLevel = $("#orderLevelInput").val();
            var beginTime = $("#beginTimeInput").val();
            var endTime = $("#endTimeInput").val();

            $('#exportExcelData-quXianName').val(quXianName);
            $('#exportExcelData-channelName').val(channelName);
            $('#exportExcelData-shopName').val(shopName);
            $('#exportExcelData-empName').val(empName);
            $('#exportExcelData-isExp').val(isExp);
            $('#exportExcelData-cityType').val(cityType);
            $('#exportExcelData-orderLevel').val(orderLevel);
            $('#exportExcelData-productCode').val(app.productCode);
            $('#exportExcelData-beginTime').val(beginTime);
            $('#exportExcelData-endTime').val(endTime);
            layer.msg('已提交导出请求，请等待结果');

            $("#exportExcel").submit();

        }


    function numAdd(num1, num2) {
        if (num1 == null || num1 == undefined || num1 == "") {
            return num2;
        }
        var baseNum, baseNum1, baseNum2;
        try {
            baseNum1 = num1.toString().split(".")[1].length;
        } catch (e) {
            baseNum1 = 0;
        }
        try {
            baseNum2 = num2.toString().split(".")[1].length;
        } catch (e) {
            baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        var precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;//精度
        return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision);
        ;
    };


    var getShopNameToSelect = function (shopQuery) {
        $.ajax({
            url: '${contextPath}/ktcount/getShopNameToSelect',
            success: function (data) {
                if (data.success) {
                    var countries = data.data
                    $('#shopNameId').autocomplete({
                        lookup: countries,
                        onSelect: function (suggestion) {
                            // alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        },
                        minChars: 0,
                    });
                }
            }
        })
    }
//    getShopNameToSelect("")

    <%--var selectEmpNameToSelected = function (channelName) {--%>
        <%--$.ajax({--%>
            <%--url: '${contextPath}/checking/selectEmpNameToSelected?channelName=' + channelName,--%>
            <%--success: function (data) {--%>
                <%--if (data.success) {--%>
                    <%--var countries = data.data--%>
                    <%--$('#empNameInput').autocomplete({--%>
                        <%--lookup: countries,--%>
                        <%--onSelect: function (suggestion) {--%>
                            <%--//console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);--%>
                            <%--getShopNameToSelect(suggestion.value)--%>
                        <%--},--%>
                        <%--width: 200,--%>
                        <%--minChars: 0,--%>
                    <%--});--%>
                <%--}--%>
            <%--}--%>
        <%--})--%>
    <%--};--%>
//    selectEmpNameToSelected('')

    var selectChannelNameToSelected = function (quXianName) {
        $.ajax({
            url: '${contextPath}/checking/selectChannelNameToSelected?quXianName=' + quXianName,
            success: function (data) {
                if (data.success) {
                    var countries = data.data
                    $('#channelNameId').autocomplete({
                        lookup: countries,
                        onSelect: function (suggestion) {
                            // alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                            selectEmpNameToSelected(suggestion.value)
                        },
                        width: 200,
                        minChars: 0,
                    });
                }
            }
        })
    }
    selectChannelNameToSelected('')

    $.ajax({
        url: '${contextPath}/checking/selectQuXianNameToSelected',
        success: function (data) {
            if (data.success) {
                var countries = data.data
                $('#quXianNameInput').autocomplete({
                    lookup: countries,
                    onSelect: function (suggestion) {
                        // alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        selectChannelNameToSelected(suggestion.value)
                    },
                    width: 200,
                    minChars: 0,
                });
            }
        }
    });

    $.ajax({
        url: '${contextPath}/page/getProductThreeName',
        success: function (data) {
            if (data.success) {
                var zNodes = data.data;

                var setting = {
                    check: {
                        enable: true,
                        chkStyle: "checkbox",
                    },

                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "ID",
                            pIdKey: "PID",
                            rootPId: '0',
                        },
                        key: {
                            name: "NAME"
                        },
                    },
                };

                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            }
        }
    })

    var selectProductTreeNames = function () {
        $("#gridSystemModal").modal('hide')
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        var nodes = zTree.getCheckedNodes();
        app.productCode = ""
        if (nodes.length == 0) {
            $("#prodNameInput").val("")
            return
        }
        var length = 0;
        for (var index in nodes) {
            var node = nodes[index]
            if (node.ISPRODNAME) {
                app.productCode = "'" + node.ID + "'," + app.productCode
                length++;
            }
        }
        app.productCode = app.productCode.substr(0, app.productCode.length - 1)
        $("#prodNameInput").val("已选择" + length + "条商品")
    }

    var selectOrderLevelToSelected = function () {
        $.ajax({
            url: '${contextPath}/checking/selectOrderLevelToSelected',
            success: function (data) {
                if (data.success) {
                    var countries = data.data
                    $('#orderLevelInput').autocomplete({
                        lookup: countries,
                        onSelect: function (suggestion) {
                            //console.log('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        },
                        //width: 200,
                        minChars: 0,
                    });
                }
            }
        })
    };
    selectOrderLevelToSelected();

    selectCityTypeToSelected('${contextPath}','#cityTypeInput', null);


    //******************* 表头固定 *********************
    // Code goes here
    'use strict'
    window.onload = function(){
        var tableCont = document.querySelector('#tableContainer')
        /**
         * scroll handle
         * @param {event} e -- scroll event
         */
        function scrollHandle (e){
//            console.log(this)
            var scrollTop = this.scrollTop;
            this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
        }

        tableCont.addEventListener('scroll',scrollHandle)
    }

    //****************************************

    //获取店铺
    var getShop = function () {
        var shopQuery = {};
        var filters = {
            "rules": [
                {
                    "field": "type",
                    "data": 'kt'
                },
                {
                    "field" : "state",
                    "data": '1'
                }
            ]
        };

        shopQuery.shopType = "'中深'";
        shopQuery.filters = JSON.stringify(filters);
        shopQuery.state = '5';
        $.ajax({
            url: '${contextPath}/ktCommon/getShopList2User',
            type: 'post',
            data: shopQuery,
            success: function (data) {
                console.log(data);
                var shopArray = []
                for(var i = 0; i < data.length; i++){
                    var shop = {}
                    shop.value = data[i].shopName;
                    shop.data = data[i].shopId;
                    shopArray.push(shop);
                }

                var countries = shopArray

                console.log(countries);
                $('#shopNameId').autocomplete({
                    lookup: countries,
                    onSelect: function (suggestion) {
                        // alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
                    },
                    minChars: 0,
                });
            },
//            success: function (data) {
//                if(data.length == 0){
//                    return;
//                }
//                var dataArray = data;
//                app.arrayShop = dataArray;
//
////                queryModel.shopId = data[0].shopId;
////                queryModel.shopId = '2889';
//
//            },
            error: function (error){
                layer.msg("获取出错："+data.message)
            }
        })
    }

    getShop();

    var getShipmentOrderOX = function () {
        console.log('获取数据');
        var quXianName = $("#quXianNameInput").val();
        var channelName = $("#channelNameId").val();
        var shopName = $("#shopNameId").val();
        var empName = $("#empNameInput").val();
        var beginTime = $("#beginTimeInput").val();
        var endTime = $("#endTimeInput").val();
        var isExp = $("#isExp").val();
        var prodType = $("#prodType").val();
        var cityType = $("#cityTypeInput").val();
        var orderLevel = $("#orderLevelInput").val();
//        if (quXianName == "" && beginTime == "" && endTime == "" && shopName == "" && channelName == "" && app.productCode == "" && orderLevel == "" && cityType == "" && prodType == "") {
//            layer.msg("请至少选择除试点店以外的一个查询条件")
//            return
//        }
        $.ajax({
            url: '${contextPath}/page/getShipmentOrderOX', //localhost:8080
            type: 'post',
            dataType: 'json',
            data: {
                stringMap: {
                    quXianName: quXianName,
                    beginTime: beginTime,
                    endTime: endTime,
                    shopName: shopName,
                    empName: empName,
                    channelName: channelName,
                    productCode: app.productCode,
                    isExp: isExp,
                    prodType: prodType,
                    orderLevel: orderLevel,
                    cityType: cityType,
                },

            },
            success: function (data) {
                if (data.success){
//                    console.log(data.data.ShipmentOrderDayData);
//                    console.log(data.data.ShipmentOrderMonthData);
//                    console.log(data.data.ShipmentOrderYearData);
                    var SPLOrderDayDataObj = data.data.ShipmentOrderDayData;
                    var SPLOrderMonthDataObj = data.data.ShipmentOrderMonthData;
                    var SPLOrderYearDataObj = data.data.ShipmentOrderYearData;
                    if (SPLOrderDayDataObj != null) {
                        updateOrderDayData(SPLOrderDayDataObj)
                        updateOrderMonthData(SPLOrderMonthDataObj)
                        updateOrderYearData(SPLOrderYearDataObj)
                    }
                }else if (data.success == undefined) {
                    window.location.href = "${contextPath}"
                }
                //console.log(data.data)
                //console.log('数据长度为：' + dataArray.length)
            },
            error: function (error) {
                //console.log(error)
            }
        })
    }

    $('#beginTimeInput').val(turnTime);
    $('#endTimeInput').val(time);
    function format(date,str){
        var mat={};
        mat.M=date.getMonth()+1;//月份记得加1
        mat.H=date.getHours();
        mat.s=date.getSeconds();
        mat.m=date.getMinutes();
        mat.Y=date.getFullYear();
        mat.D=date.getDate();
        mat.d=date.getDay();//星期几
        mat.d=check(mat.d);
        mat.H=check(mat.H);
        mat.M=check(mat.M);
        mat.D=check(mat.D);
        mat.s=check(mat.s);
        mat.m=check(mat.m);
        if(str.indexOf(":")>-1){
            mat.Y=mat.Y.toString().substr(2,2);
            return mat.Y+"/"+mat.M+"/"+mat.D;
        }
        if(str.indexOf("/")>-1){
            return mat.Y+"/"+mat.M+"/"+mat.D+" "+mat.H+"/"+mat.m+"/"+mat.s;
        }
        if(str.indexOf("-")>-1){
            return mat.Y+"-"+mat.M+"-"+mat.D+ " "+mat.H+":"+mat.m+":"+mat.s;
        }
        if(str.indexOf("_")>-1){
            return mat.Y+"-"+mat.M+"-01 00:00:00";
        }
    }
    //检查是不是两位数字，不足补全
    function check(str){
        str=str.toString();
        if(str.length<2){
            str='0'+ str;
        }
        return str;
    }


</script>
</html>





